package com.atguigu.springcloud.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class MyGatewayFilter implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        // 情景设定：打印当前请求路径
        // 1、获取请求对象
        ServerHttpRequest request = exchange.getRequest();

        // 2、获取请求路径
        RequestPath path = request.getPath();

        // 3、打印请求路径
        System.out.println("path = " + path);

        // 4、放行
        return chain.filter(exchange);
    }
}
